Repository navigation
Conversation
InferenceClient, HTTPClient and the authentication token requests now send requests with allow_redirects=False. A 3xx response raises InferenceClientError or APIException. AsyncInferenceExecution.status_json() and result() now use the client timeout and raise on an HTTP error status. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
InferenceClient(follow_redirects=True) follows a redirect only if the target is inside the deployment: same scheme, host and port as endpoint_base_url, a path under the deployment path, and no relative path segment in the Location path. It follows at most 5 redirects. Any other redirect raises InferenceClientError. The default stays off. AsyncInferenceExecution status and result never follow a redirect. HTTPClient and the authentication calls do not change. When a redirect only adds or removes a trailing slash, the error message tells the caller to change path. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ects-34af24 # Conflicts: # CHANGELOG.md # tests/unit_tests/inference_client/test_inference_client.py
With follow_redirects on, the part of the target path under the deployment must now pass check_request_path with the same allowlist as path. Forms such as `..;/`, `%`-escapes and `\` are rejected. The query string is not checked. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The SDK clients do not follow HTTP redirects by default. A 3xx response raises an error.
InferenceClienthas a new opt-in argument,follow_redirects(defaultFalse). When it is on, the client follows a redirect only if all of these are true:endpoint_base_url.<deployment path>/.Locationpath has no relative segment, plain or encoded.path. Forms such as..;/,%-escapes and\are rejected. The query string is not checked.The client raises
InferenceClientErrorfor any other redirect.requestsmethod rules apply: 303 changes to GET, 301 and 302 change POST to GET, and 307 and 308 keep the method and body.status_json()andresult()never follow a redirect.HTTPClientand the authentication calls do not get the option.When a redirect only adds or removes a trailing slash, the error message tells you to change
path.status_json()andresult()also use the clienttimeout_secondsnow.Evidence
Unit test, for each client method and each status 301, 302, 303, 307 and 308:
/moved. The test fails.After: the client sends one request and raises
InferenceClientError. The test passes.Unit tests for
follow_redirects=True:..,%2e%2e,..%2F,..;/and..%252fsegments, characters thatpathdoes not allow, another host,httpinstead ofhttps, another port, and user info.status_json()andresult()do not follow a redirect.Tested locally:
uv run pytest tests/unit_tests: 624 passed, with security: check the inference request path with the API path rules #103 merged.uv run ruff checkanduv run ruff format --check: pass.Location. A request without a mismatch gets 200 before and after.Merge Danger
Door: two-way
A revert restores the old behavior.
Blast Radius: consumers
These cases can break:
http://base URL that the server redirects tohttps://. The call now raises an error.follow_redirects=Truedoes not help here, because the scheme changes.path. If the container sends aLocationinside the deployment,InferenceClient(..., follow_redirects=True)restores the old behavior.status_json()andresult()now raise on a 4xx or 5xx response. They also stop aftertimeout_seconds(default 300 seconds).HTTPClientmethods ignoreallow_redirects=True.🤖 Generated with Claude Code